<template>
	<view class="login">
		<!-- 广告 -->
		<view class="advertise">
			<view>登陆恋爱吧</view>
			<view class="title_copy">
				<text>成为知心爱人</text>
				<text>共建心灵港湾</text>
			</view>
		</view>
		<!-- 登陆/注册 -->
		<view class="logReg">
			<logReg @clickCode="clickCode" @clickBtn="clickBtn" @goReg="goReg" @forget="forget" :type="datas.type" :code="datas.code"></logReg>
		</view>
	</view>
</template>

<script setup>
	import {onMounted, reactive, ref} from "vue";
	import {codeReq} from "@/api/user.js";
	import { useStore } from "vuex";
	//vuex
	const store=useStore()
	// 数据
	const datas=reactive({
		type:'login',
		code:''
	})
	// 用户注册的数据
	const regData=ref({})
	// 点击了登陆按钮
	const clickBtn=(val,data)=>{
		if(datas.type=='login') {
			store.dispatch('user/A_login',val)
		}else if(datas.type=='reg'){
			regData.value={...regData.value,...data}
			datas.type=val
		}else if(datas.type=='fillin'){
			regData.value={...regData.value,...data}
			datas.type=val
		}else if(datas.type=='objective'){
			// 组装数据发请求
			regData.value={...regData.value,...data}
			store.dispatch('user/A_reg',regData.value).then(res=>{
				datas.type=res
			}).catch(err=>{
				datas.type=res
			})
		}
	}
	//点击了前往注册
	const goReg=(val)=>{
		datas.type=val
	}
	//点击了忘记密码
	const forget=(val)=>{
		datas.type=val
	}
	// 点击发送验证码
	const clickCode=async(data)=>{
		let res = await codeReq(data)
		datas.code=res.data.data.code
		uni.showToast({
			title: res.data.data.code,
			icon:"success"
		});
	}
	onMounted(() => {
		// getcode()
		
	
	})
</script>

<style lang="scss">
	.login {
		width: 100%;
		height: 100%;
		.advertise {
			padding: 30rpx;
			height: 150rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			align-content: space-between;
			color: #fff;
			background:#0084ff;
			font-size: 22px;
			.title_copy {
				width: 100%;
				margin-top: 30rpx;
				display: flex;
				justify-content: space-evenly;
				font-size: 16px
			}
		}
		.logReg{
			padding: 50rpx 30rpx;
		}
	}
</style>
